// 导入express模块
var express = require("express");
var fs = require("fs");
var db = require("../db/db.js");

// 生成路由
var router = express.Router();

// 网站首页路由
router.get('/', (req, res) => {
    // 读取一个目录
    db.Question.find()
        .populate("createUser")
        .populate({
            path: 'answers',
            populate: {
                path: 'createUser',
                select: '-password'
            }
        })
        .exec(function(err, data) {
            var questions = data.map(function(elem) {
                return elem.toObject()
            })
            questions.reverse()
            // console.log(questions[0]._id);
            res.render("index", {
                title: "首页-问答系统",
                privateJs: "index",
                data: data
            })
        });

    // files所有的文件名数组

})
module.exports = router;
